<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <el-col :span="12">
          <el-input placeholder="请输入内容" v-model="queryinfo.query" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table border stripe :data="orderList" style="width: 100%">
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="100"></el-table-column>
        <el-table-column label="是否付款" width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.pay_status!=='0'" type="success">已付款</el-tag>
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="100"></el-table-column>
        <el-table-column label="下单时间" width="180">
          <template slot-scope="scope">{{scope.row.update_time | getDate}}</template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-edit"
              @click="showChangeVisible(scope.row.order_id)"
            ></el-button>
            <el-button
              type="success"
              size="mini"
              icon="el-icon-location"
              @click="showPreviewdialog(scope.row.order_id)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleChange"
        @current-change="handleChange"
        :current-page.sync="queryinfo.pagenum"
        :page-sizes="[10, 20, 30, 50]"
        :page-size.sync="queryinfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <el-dialog
      title="修改地址"
      :visible.sync="changeAddressdialogVisible"
      width="30%"
      @close="addvisibleClose"
    >
      <el-form :model="changeAddForm" :rules="rules" ref="changeAddFormFef" label-width="100px">
        <el-form-item label="省市区/县" prop="address">
          <el-cascader
            v-model="changeAddForm.address"
            :options="cityDate"
            :props="changeAddProp"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="detailaddress">
          <el-input v-model="changeAddForm.detailaddress"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="changeAddressdialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="changeAddressdialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="查看物流" :visible.sync="showPreviewdialogVisible" width="30%">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in ExpressInfo"
          :key="index"
          :timestamp="activity.time"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>
<script>
import cityDate from "./citydate.js";
export default {
  data() {
    return {
      orderList: [],
      total: 0,
      queryinfo: {
        query: "",
        pagenum: 1,
        pagesize: 10,
        user_id: "",
        pay_status: "",
        is_send: "",
        order_fapiao_title: "",
        order_fapiao_company: "",
        order_fapiao_content: "",
        consignee_addr: ""
      },
      changeAddressdialogVisible: false,
      changeAddForm: {
        address: "",
        detailaddress: ""
      },
      rules: {
        address: [
          { required: true, message: "请输入省市区/县", trigger: "blur" }
        ],
        detailaddress: [
          { required: true, message: "请输入详细地址", trigger: "blur" }
        ]
      },
      cityDate,
      changeAddProp: {
        value: "value",
        label: "label",
        expandTrigger: "hover"
      },
      showPreviewdialogVisible: false,
      ExpressInfo:[],
      currentExpressId:0
    };
  },
  methods: {
    handleChange() {
      this.getOrderList();
    },
    async getOrderList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryinfo
      });
      if (res.meta.status !== 200) {
        return this.$message.error("获取订单列表失败");
      }
      this.orderList = res.data.goods;
      this.total = res.data.total;
    },
    showChangeVisible() {
      this.changeAddressdialogVisible = true;
    },
    showPreviewdialog(id) {
        console.log(id);
      this.currentExpressId = id;  
      this.showPreviewdialogVisible = true;
      this.getExpressInfo()
    },

    addvisibleClose() {
      this.$refs.changeAddFormFef.resetFields();
    },
    // 获取物流信息
    async getExpressInfo(){
        const {data :res} = await this.$http.get(`/kuaidi/${1106975712662}`)
        console.log(res);
        
        this.ExpressInfo = res.data;
        

    }
  },
  created() {
    this.getOrderList();
  }
};
</script>
<style lang="less" scoped>
.el-cascader {
  width: 100%;
}
</style>